package edu.xidian.bdilab.jrbigdata.service.enterprise.productCheck.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import edu.xidian.bdilab.jrbigdata.domain.FinancialProduct;
import edu.xidian.bdilab.jrbigdata.domain.ProductRequest;
import edu.xidian.bdilab.jrbigdata.mapper.FinancialProductMapper;
import edu.xidian.bdilab.jrbigdata.mapper.ProductRequestMapper;
import edu.xidian.bdilab.jrbigdata.service.enterprise.productCheck.ProductCheckService;
//import org.omg.CORBA.INTERNAL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName ProductCheckServiceImpl
 * @Description TODO
 * @Author tuantuan
 * @Date 2019/3/30 下午9:36
 * @Version 1.0
 * @Attention Copyright (C), 2004-2019, BDILab, XiDian University
 **/
@Service
public class ProductCheckServiceImpl implements ProductCheckService {
    @Autowired
    FinancialProductMapper financialProductMapper;
    @Autowired
    ProductRequestMapper productRequestMapper;


    @Override
    public List<FinancialProduct> checkProduct(Integer institution_type, Integer loanLimit, Integer loan_period,
                                              Integer guarantee_mode, Integer internet_loan_type, Integer product_properties, String socialCode) {

//        FinancialProduct financialProduct;
        QueryWrapper<FinancialProduct> productQueryWrapper = new QueryWrapper<>();
        QueryWrapper<ProductRequest> requestQueryWrapper = new QueryWrapper<>();

        ArrayList<FinancialProduct> financialProductList;
        ArrayList<ProductRequest> requestList;
        ArrayList<String> requestProductName = new ArrayList<>();

        //先查出来金融产品
        productQueryWrapper.eq(institution_type!=null,"institution_type", institution_type)
                .eq(loanLimit!=null,"loan_limit", loanLimit)
                .like(loan_period!=null,"loan_period", loan_period)
                .eq(guarantee_mode!=null,"guarantee_mode", guarantee_mode)
                .eq(internet_loan_type!=null,"internet_loan_type", internet_loan_type)
                .eq(product_properties!=null,"product_properties", product_properties);

        //查出来企业已有的产品申请
        requestQueryWrapper.eq("fk_social_code",socialCode);
        requestList = (ArrayList<ProductRequest>) productRequestMapper.selectList(requestQueryWrapper);
        for(ProductRequest productRequest: requestList){
            productQueryWrapper.ne("product_name", productRequest.getFkProductName());
        }

        financialProductList = (ArrayList<FinancialProduct>) financialProductMapper.selectList(productQueryWrapper);

        return financialProductList;
    }
}
